import type * as Store from './type'
import http from '@/utils/http'

const BASE_URL = '/store/product'


export interface StoreProductPageQuery extends Store.StoreProductQuery, PageQuery {}

/** @desc 查询商品列表 */
export function listStoreProduct(query: StoreProductPageQuery) {
  return http.get<PageRes<Store.StoreProductResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询商品详情 */
export function getStoreProduct(id: string) {
  return http.get<Store.StoreProductDetailResp>(`${BASE_URL}/${id}/info`)
}

/** @desc 新增商品 */
export function addStoreProduct(data: any) {
  return http.post(`${BASE_URL}/create`, data)
}

/** @desc 修改商品 */
export function updateStoreProduct(data: any) {
  return http.post(`${BASE_URL}/update`, data)
}

/** @desc 删除商品 */
export function deleteStoreProduct(id: string) {
  return http.del(`${BASE_URL}/${id}`)
}

/** @desc 下架商品 */
export function putOffStoreProduct(id: string) {
  return http.patch(`${BASE_URL}/${id}/shell/off`)
}

/** @desc 上架商品 */
export function putOnStoreProduct(id: string) {
  return http.patch(`${BASE_URL}/${id}/shell/on`)
}

/** @desc 商品表头数量 */
export function getTabsHeader() {
  return http.get(`${BASE_URL}/tabs/headers`)
}

/** @desc 导出商品 */
export function exportStoreProduct(query: Store.StoreProductQuery) {
  return http.download<any>(`${BASE_URL}/export`, query)
}
